const mysql = require('mysql2');

const options = {
    host: 'localhost',
    user: 'root',
    password: '' ,
    database: 'wendao',
    waitForConnections: true,
    connectionLimit: 10,
    queueLimit: 0
}

const pool = mysql.createPool( options );

async function test( sql ){
    console.log( 'test' );
    let promise = new Promise( (resolve,reject)=>{
        pool.execute( sql , async (error,results,fields)=>{
            if( error ) {
                reject( error );
                return ;
            }
            resolve( results );
        });
    });
    return promise ;
}
console.log( 'begin' );
let sql = 'SELECT title FROM t_topics' ;
let p = test( sql );
p.then( value => console.log( 'value: ' , value ) )
    .catch( error => console.log( error ) )
    .finally( ()=> pool.end() );
console.log( 'end' );
